package com.zhz.project.main.socolar.wenzhang.util;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.tags.FrameTag;
import org.htmlparser.util.NodeList;

public class FullTextUrlParser {

    String content = null;

    public String parse() {

        try {
            Parser parser = new Parser(content);

            NodeFilter[] nodeFilter = new NodeFilter[2];

            nodeFilter[0] = new TagNameFilter("frame");

            nodeFilter[1] = new HasAttributeFilter("scrolling", "auto");

            AndFilter andFilter = new AndFilter(nodeFilter);

            NodeList list = parser.extractAllNodesThatMatch(andFilter);
            if (list != null && list.size() > 0) {
                Node node = list.elementAt(0);
                if (node instanceof FrameTag) {
                    FrameTag frameTag = (FrameTag) node;
                    String src = frameTag.getAttribute("src");
                    return src;
                }
            }
        } catch (Exception e) {
            //            System.out.println(e.toString());
        }
        return null;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

}
